#! /usr/bin/python3
# -*- coding: UTF-8 -*-

if __name__ == "__main__":
	raise Exception("不支持从这里调用")

__version__ = "1.0"
__all__ = []

import os

from com.mousechsh.common.data.json.MouseChshJson import mousechsh_json_to_json
from com.mousechsh.common.io.file.MouseChshFile import mousechsh_file_read_text
from com.mousechsh.common.middle.http.MouseChshHttpHeader import mousechsh_http_header_accept_language_annotation
from com.mousechsh.common.middle.router.MouseChshHttpRouter import (
	mousechsh_http_router_annotation,
	mousechsh_http_router_scan_files,
)

_mousechsh_web_server_router_flag = True


@mousechsh_http_router_annotation(method='GET', path='/')
@mousechsh_http_header_accept_language_annotation()
def index(url, request, response, *argsArr, **argsDict):
	global _mousechsh_web_server_router_flag
	response.get_header().set_content_type_('html').set_content_type_options()
	path = os.path.abspath(os.path.join(
		os.path.dirname(__file__),
		'../../../../../../mousechsh_web'
	))
	if _mousechsh_web_server_router_flag:
		mousechsh_http_router_scan_files(path)
	_mousechsh_web_server_router_flag = False
	path = os.path.join(path, 'MouseChsh.html')
	response.set_body(mousechsh_file_read_text(path))


@mousechsh_http_router_annotation(method='GET', path='/bg')
@mousechsh_http_header_accept_language_annotation()
def index(url, request, response, *argsArr, **argsDict):
	# Bing壁纸：https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1
	response.get_header().set_content_type_('json').set_content_type_options()
	response.set_body(mousechsh_json_to_json({
		'url': 'https://cn.bing.com/th?id=OHR.LontraCanadensis_ZH-CN3359002168_1920x1080.jpg&rf=LaDigue_1920x1080.jpg&pid=hp'
	}))
